package com.szholly.pro.watergas_server.ps.android.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

import com.szholly.plug.form.core.interceptor.FormEditInterceptorClass;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.szholly.pro.watergas_server.common.data.DataUtil;
import com.szholly.pro.watergas_server.common.util.RedisHelper;
import com.szholly.utils.spring.SpringBeanFactory;
import com.szholly.utils.util.JSONUtils;
import com.szholly.utils.util.StringUtils;
import com.szholly.data.common.util.ConvertCaptionUtils;
import com.szholly.data.common.util.JSONConvertUtils;
import com.szholly.data.general.GlobalParameter;
import com.szholly.data.general.ITable;
import com.szholly.data.general.ITableFactory;
import com.szholly.data.general.RowBase;
import com.szholly.data.general.interceptor.DbEditType;

import lrq.common.PropertiesUnit;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Service
public class SupplyWaterService {
	/**
	 * 供水 SecondActivity初始化所需的数据 获取组长名字 获取签名路径 获取单位列表
	 */
	@RequestMapping("/getSupplySecondInit")
	@ResponseBody
	public String getSupplySecondInit(String groupId) {
		JSONObject resultJson = new JSONObject();
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();

		// 签名照路径
		String sql = "select t.c_userealname,t.s_orgid,t.s_userid,t.sign_img from safe_user t";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() > 0) {
			String result = JSONUtils.toJSONString(rows);
			resultJson.put("signPathInfo", result);
		} else {
			resultJson.put("signPathInfo", "[]");
		}

		// 获取组长的名字
		if (groupId != null && !groupId.isEmpty()) {
			sql = "select t2.c_userealname,t1.user_id from OC_GROUP_ASSO t1 left join SAFE_USER t2 on"
					+ " t1.user_id=t2.s_userid where t1.group_head='1' ";
			sql += " and t1.group_id=@groupId";
			parms.add(new GlobalParameter("groupId", groupId));
			rows = DataUtil.getSelectRows(sql, parms);
			if (rows != null && rows.size() >= 0) {
				RowBase rowBase = rows.get(0);
				JSONObject o = new JSONObject();
				o.put("C_USEREALNAME", rowBase.getValue("C_USEREALNAME"));
				o.put("USER_ID", rowBase.getValue("USER_ID"));
				resultJson.put("leaderInfo", o);
			} else {
				resultJson.put("leaderInfo", "{}");
			}
		} else {
			resultJson.put("leaderInfo", "{}");
		}
		parms.clear();

		// 加载单位列表
		sql = "select t.S_DOMAINCODE,t.S_DOMAINCAPTION,t.s_unit from data_defulatdomain t where t.S_DOMAINNAME = 'MONITOR_PARAM'";
		rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			resultJson.put("unitInfo", JSONUtils.toJSONString(rows));
		} else {
			resultJson.put("unitInfo", "[]");
		}

		// 返还结果
		return resultJson.toString();
	}
	/**
	 * 供水公司列表接口 该数据显示在第二个界面 SecondActivity
	 */

	public String getSupplyWaterCompanyList(String groupId) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t.name STATION_NAME,t.code STATION_CODE,t2.name FACTORY_NAME,t.WWTP_ID FACTORY_CODE "
				+ "from BC_SITE_INFO t left join (select t1.STATION_ID from OPERATION_GROUP_STATION_ASSO t1";
		if (groupId != null && !groupId.isEmpty()) {
			sql += " where OPERATION_GROUP_ID = '" + groupId + "'";
		}
		sql += ") t1 ON t.CODE = t1.STATION_ID left join(select EXP_NO,name from BC_ENTERPRISE_ATTR where POLL_TYPE = '3')t2 ON t2.EXP_NO = t.WWTP_ID "
				+ "where t.STATION_CATEGORY = '3' and t1.STATION_ID IS NOT NULL AND t2.name IS NOT NULL ORDER BY t.WWTP_ID";
		List<RowBase> rowList = DataUtil.getSelectRows(sql, parms);
		if (rowList == null) {
			return "[]";
		}
		List<HashMap<String, Object>> resultList = new ArrayList<HashMap<String, Object>>();
		// 父类字段 factoryName factoryId count stationList
		// 子类字段 stationName stationId
		HashMap<String, Object> factoryMap = null;
		HashMap<String, String> stationMap = null;
		List<HashMap<String, String>> stationList = null;
		for (RowBase bean : rowList) {
			try {
				// 遍历分类
				String factroyId = bean.getValue("FACTORY_CODE").toString();
				if (factoryMap == null || !factroyId.equals(factoryMap.get("factoryId"))) {
					factoryMap = new HashMap<String, Object>();
					stationList = new ArrayList<HashMap<String, String>>();
					factoryMap.put("count", 0);
					factoryMap.put("stationList", stationList);
					factoryMap.put("factoryName", bean.getValue("FACTORY_NAME").toString());
					factoryMap.put("factoryId", factroyId);
					resultList.add(factoryMap);
				}
				stationMap = new HashMap<String, String>();
				stationMap.put("stationId", bean.getValue("STATION_CODE").toString());
				stationMap.put("stationName", bean.getValue("STATION_NAME").toString());
				int count = (int) factoryMap.get("count") + 1;
				factoryMap.put("count", count);
				stationList.add(stationMap);
			} catch (Exception e) {
			}
		}
		JSONArray jsonArray = JSONArray.fromObject(resultList);
		if (jsonArray == null) {
			return "[]";
		} else {
			return jsonArray.toString();
		}
	}
	/**
	 * 供水 访问频率：一般 获取站点列表
	 */
	public String getSupplyStation(String groupId, String factoryId) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		parms.add(new GlobalParameter("groupId", groupId));
		parms.add(new GlobalParameter("factoryId", factoryId));
		// 获取报警状态 1 表示有报警
		String sql = "select t.name \"name\",t1.STATION_ID \"id\",NVL(t2.num ,0) as \"num\" from BC_SITE_INFO t "
				+ "left JOIN(select STATION_ID,COUNT(STATION_ID) AS num from OP_TASK  where TASK_STATUS = '0' group by STATION_ID)t2 "
				+ "on t2.STATION_ID = t.CODE "
				+ "left join(select DISTINCT   STATION_ID from OPERATION_GROUP_STATION_ASSO where 1=1";
		if (!groupId.isEmpty()) {
			sql += "and OPERATION_GROUP_ID = @groupId ";
		}
		sql += ")t1 on t1.STATION_ID = t.CODE where WWTP_ID = @factoryId and t1.STATION_ID IS NOT NULL";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "[]";
		}
	}
	/**
	 * 获取设备是否在线, 0正常、1超标、2异常、3故障
	 */
	public String getGsIfOnline() {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sqlmn = "select t1.device_num,t1.site_id from BC_COLLECTION_INFO t1,"
				+ " monitor_station t2 where t1.site_id = t2.exp_no and t2.station_category='3'";
		List<RowBase> rowmn = DataUtil.getSelectRows(sqlmn, parms);
		JSONObject jsonObj = new JSONObject();
		if (rowmn.size() > 0) {
			for (int i = 0; i < rowmn.size(); i++) {
				String mn = rowmn.get(i).getSafeString("DEVICE_NUM");
				String status = RedisHelper.getInstance().getStationStatus(mn);
				jsonObj.put(rowmn.get(i).getSafeString("site_id"), status);
			}
		}

		return JSONUtils.toJSONString(jsonObj);
		// String status = RedisHelper.getInstance().getStationStatus(mn);
	}
	/**
	 * android移动运营初始化供水异常
	 * 
	 * @param userName
	 * @param password
	 * @return
	 * @throws Exception
	 */
	public String initGsWarn(String groupId) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t1.s_domaincaption,t2.s_domaincaption,t3.name,t3.exp_no,t.alarm_value,t.alarm_text,to_char(t.START_TIME,'yyyy-MM-dd HH24:MI:SS')as lastupdatetime,t.CONTINUE_TIME from OP_ALAR_INFO t "
				+ "left join (select S_DOMAINCODE,S_DOMAINCAPTION from data_defulatdomain d where S_DOMAINNAME='报警类型') t1 on t.type= t1.s_domaincode "
				+ "left join (select S_DOMAINCODE,S_DOMAINCAPTION from data_defulatdomain d where S_DOMAINNAME='MONITOR_PARAM') t2 on t.param = t2.s_domaincode  "
				+ "left join (select name,exp_no from BC_SITE_INFO  where STATION_CATEGORY = '3' ) t3 on t.station_code = t3.exp_no "
				+ "left join OPERATION_GROUP_STATION_ASSO t4 on t.station_code = t4.station_id "
				+ "where  t.is_recover ='0'and t.continue_time>30 ";
		if (null != groupId && !groupId.isEmpty()) {
			sql += " and t4.operation_group_id = @groupId ";
			parms.add(new GlobalParameter("groupId", groupId));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() > 0) {
			String result = JSONUtils.toJSONString(rows);
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}
	/**
	 * 根据站点获取供水异常参数名称
	 * 
	 * @param flow_type
	 * @param wwtp_id
	 * @return
	 */
	public String getGsAbnormal() {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t.s_domaincode,t.s_domaincaption from data_defulatdomain t where t.s_domainname='供水异常故障项'";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}
	/**
	 * 根据站点获取供水在线设备
	 * 
	 * @param flow_type
	 * @param wwtp_id
	 * @return
	 */
	@RequestMapping("/getGSEquipmentByStation")
	@ResponseBody
	public String getGSEquipmentByStation(String EXP_NO) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t3.S_DOMAINCAPTION,t1.guid,t1.name,t1.DEVICE_TYPENUM,t1.DEVICE_NUM,"
				+ "t1.MONITOR_POLLUTANTS ,t4.DENSITY_ALARM_DOWMLIMIT,t4.DENSITY_ALARM_UPLIMIT,"
				+ "t4.ABNORMAL_MIN,t4.ABNORMAL_MAX  from BC_SITE_DEVICE_RPT t1 "
				+ "left join BC_SITE_INFO t2 on t1.monitor_point=t2.exp_no "
				+ "left join (select t.S_DOMAINCODE,t.S_DOMAINCAPTION  from data_defulatdomain  "
				+ "t  where t.S_DOMAINNAME='MONITOR_PARAM') t3 on t3.s_domaincode = t1.MONITOR_POLLUTANTS  "
				+ "left join BC_SITE_POLL  t4 on t4.site_id = t1.monitor_point "
				+ "and t4.name = t1.MONITOR_POLLUTANTS where 1=1 ";
		if (EXP_NO != null && !EXP_NO.equals("")) {
			sql += " and t2.EXP_NO =@EXP_NO";
			parms.add(new GlobalParameter("EXP_NO", EXP_NO));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}
	/**
	 * 供水 签到
	 * 
	 * @return 0:签到失败 1:签到成功
	 */
	@RequestMapping("/getSupplyWaterSignInResult")
	@ResponseBody
	public String getSupplyWaterSignInResult(String row) {
		JSONObject resultObject = new JSONObject();
		resultObject.put("result", "0");
		if (row == null || row.isEmpty()) {
			return resultObject.toString();
		}
		JSONObject rowJson = JSONUtils.toJSONObject(row);
		try {
			String signInRange = PropertiesUnit.getValue("distance");
			String distanceStr = rowJson.getString("distance");
			double distance = Double.parseDouble(distanceStr);
			double distanceNormal = Double.parseDouble(signInRange);
			// 距离太远不能签到
			if (distance > distanceNormal) {
				return resultObject.toString();
			}
		} catch (Exception e) {
		}
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		parms.add(new GlobalParameter("stationId", rowJson.getString("stationId")));
		// parms.add(new GlobalParameter("stationName",
		// rowJson.getString("stationName")));
		parms.add(new GlobalParameter("x", rowJson.getString("x")));
		parms.add(new GlobalParameter("y", rowJson.getString("y")));
		parms.add(new GlobalParameter("dateTime", rowJson.getString("dateTime")));
		parms.add(new GlobalParameter("userId", rowJson.getString("userId")));
		parms.add(new GlobalParameter("groupId", rowJson.getString("groupId")));
		parms.add(new GlobalParameter("address", rowJson.getString("address")));
		String sql = "INSERT INTO OP_SUPPLY_SIGN_IN" + " (GUID,STATION_ID,X,Y,USER_ID,GROUP_ID,SIGNIN_TIME,ADDRESS)"
				+ " VALUES (SYS_GUID(),@stationId,@x,@y,@userId,@groupId,@dateTime,@address)";
		int i = DataUtil.ExecuteUpdateSql(sql, parms);
		if (i == 0) {
			resultObject.put("result", "1");
		} else {
			resultObject.put("result", "0");
		}
		return resultObject.toString();
	}
	/**
	 * 供水 判断是否签到 signCount 获取站点坐标 x,y
	 * 
	 * @return signCount:-1 表示不需要签到 0表示未签到
	 */
	@RequestMapping("/getSupplyWaterInitTask")
	@ResponseBody
	public String getSupplyWaterInitTask(String stationId, String groupId) {
		JSONObject resultObject = new JSONObject();
		resultObject.put("signCount", "0");
		resultObject.put("x", "0");
		resultObject.put("y", "0");
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		parms.add(new GlobalParameter("stationId", stationId));
		parms.add(new GlobalParameter("groupId", groupId));
		if (!stationId.isEmpty()) {
			String signSql = "select X,Y from SUPPLY_SIGN_IN WHERE STATION_ID = @stationId ";
			List<RowBase> rows = DataUtil.getSelectRows(signSql, parms);
			if (rows != null && rows.size() >= 0) {
				RowBase rowBase = rows.get(0);
				if (rowBase != null) {
					resultObject.put("x", rowBase.getValue("X"));
					resultObject.put("y", rowBase.getValue("Y"));
				}
			}
			if (!groupId.isEmpty()) {
				String coordSql = "select SIGNIN_TIME from OP_SUPPLY_SIGN_IN where STATION_ID = @stationId and GROUP_ID = @groupId and TO_CHAR(to_date(SIGNIN_TIME,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd')=TO_CHAR(SYSDATE,'yyyy-mm-dd')";
				rows = DataUtil.getSelectRows(coordSql, parms);
				if (rows != null && rows.size() >= 0) {
					resultObject.put("signCount", String.valueOf(rows.size()));
				}
			} else {
				resultObject.put("signCount", "1");
			}
		}
		return resultObject.toString();
	}
	/**
	 * 获取上次维护时间
	 */
	@RequestMapping("/getLastWhDate")
	@ResponseBody
	public String getLastWhDate(String stationId) {
		if (stationId.isEmpty()) {
			return "[]";
		}
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select to_char(t.ASSERTTIME,'yyyy-MM-dd HH24:MI:SS')as ASSERTTIME from BC_SITE_INFO t where exp_no = @stationId";
		parms.add(new GlobalParameter("stationId", stationId));
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() > 0) {
			String result = JSONUtils.toJSONString(rows);
			return JSONUtils.toJSONString(rows);
		} else {
			return "[]";
		}
	}
	/**
	 * 根据站点获取数据比对污染物参数
	 * 
	 * @param flow_type
	 * @param wwtp_id
	 * @return
	 */
	@RequestMapping("/getGSSJBDByStation")
	@ResponseBody
	public String getGsSjbdDataByStation(String EXP_NO) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "SELECT t1.s_domaincaption,t1.s_domaincode from BC_SITE_POLL t left join "
				+ "(select t.S_DOMAINCODE,t.S_DOMAINCAPTION  from data_defulatdomain  t  "
				+ "where S_DOMAINNAME='深圳供水参数') t1 on t.name = t1.S_DOMAINCODE  where 1= 1  ";
		if (EXP_NO != null && !EXP_NO.equals("")) {
			sql += " and t.SITE_ID =@EXP_NO";
			parms.add(new GlobalParameter("EXP_NO", EXP_NO));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}
	/**
	 * 保存一致性数据
	 * 
	 * @return 0：保存失败
	 */
	@RequestMapping("/saveSignatureData")
	@ResponseBody
	public String saveSignatureData(String row, String stationId, String DATETIME, String userID, String THANDATE,
			String ASSERTTIME) {
		// 默认返回保存失败
		JSONObject resultJson = new JSONObject();
		resultJson.put("result", "0");
		if (row.isEmpty() || stationId.isEmpty() || DATETIME.isEmpty() || userID.isEmpty()) {
			// 参数不合法，保存失败
			return resultJson.toString();
		}

		Date date = null;
		Date tdate = null;
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			tdate = sdf.parse(THANDATE);
			date = sdf.parse(DATETIME);
		} catch (ParseException e) {
			System.out.println(e.getMessage());
		}
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		parms.add(new GlobalParameter("STATIONID", stationId));
		parms.add(new GlobalParameter("USERID", userID));
		parms.add(new GlobalParameter("THANDATE", tdate));
		parms.add(new GlobalParameter("DATETIME", date));
		String querySql = "select STATIONID from COHERENCEDATA "
				+ "WHERE DATETIME = @DATETIME AND STATIONID = @STATIONID AND USERID = @USERID";
		List<RowBase> rows = DataUtil.getSelectRows(querySql, parms);
		if (rows != null && rows.size() > 0) {
			// 表示重复保存，保存失败
			return resultJson.toString();
		}
		if (null != ASSERTTIME && !ASSERTTIME.isEmpty()) {
			Date tdate_1 = null;
			try {
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				tdate_1 = sdf.parse(ASSERTTIME);
			} catch (ParseException e) {
				System.out.println(e.getMessage());
			}
			String whSql = "update monitor_station set ASSERTTIME = @tdate where exp_no = @stationId";
			parms.add(new GlobalParameter("tdate", tdate_1));
			parms.add(new GlobalParameter("stationId", stationId));
			int i = DataUtil.ExecuteUpdateSql(whSql, parms);
			if (i != 0) {
				return resultJson.toString();
			}
		}
		JSONArray list = JSONUtils.toJSONArray(row);
		int f = 0;
		for (int i = 0; i < list.size(); i++) {
			String PARMNAME = list.getJSONObject(i).optString("PARMNAME");
			String RTD = list.getJSONObject(i).optString("RTD");
			String VALUE = list.getJSONObject(i).optString("VALUE");
			String Sql = "insert into COHERENCEDATA(PARMNAME,RTD,VALUE,STATIONID,DATETIME,USERID,THANDATE) values "
					+ "(@PARMNAME,@RTD,@VALUE,@STATIONID,@DATETIME,@USERID,@THANDATE)";
			parms.add(new GlobalParameter("PARMNAME", PARMNAME));
			parms.add(new GlobalParameter("RTD", RTD));
			parms.add(new GlobalParameter("VALUE", VALUE));
			f = f + DataUtil.ExecuteUpdateSql(Sql, parms);
		}
		if (f == 0) {
			resultJson.put("result", "1");
		}
		return resultJson.toString();
	}
	/*
	 * 获取平台实时在线数值
	 */
	@RequestMapping("/getRealValue")
	@ResponseBody
	public String getRealValue(String stationId, String time) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t1.site_id,to_char(t.datatime,'yyyy-mm-dd hh24:mi:ss')as datatime,t.mn,t.parmname,t.rtd from monitor_data t "
				+ "left join BC_COLLECTION_INFO t1 on t.mn = t1.device_num where 1=1";
		if (null != stationId && !stationId.isEmpty()) {
			sql += " and t1.site_id = @stationId ";
			parms.add(new GlobalParameter("stationId", stationId));
		}
		if (null != time && !time.isEmpty()) {
			sql += " and datatime = to_date(@time,'yyyy-mm-dd hh24:mi:ss') ";
			parms.add(new GlobalParameter("time", time));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() > 0) {
			String result = JSONUtils.toJSONString(rows);
			return JSONUtils.toJSONString(rows);
		} else {
			String sql1 = "select t1.site_id,to_char(t.datatime,'yyyy-mm-dd hh24:mi:ss')as datatime,t.mn,t.parmname,t.rtd from monitor_data t "
					+ "left join BC_COLLECTION_INFO t1 on t.mn = t1.device_num where 1=1";
			if (null != stationId && !stationId.isEmpty()) {
				sql1 += " and t1.site_id = @stationId ";
				parms.add(new GlobalParameter("stationId", stationId));
			}
			if (null != stationId && !stationId.isEmpty()) {
				sql1 += " and datatime = to_date(@time,'yyyy-mm-dd hh24:mi:ss')";
				Date rtn = null;
				GregorianCalendar cal = new GregorianCalendar();
				Date date = null;
				try {
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					date = sdf.parse(time);
				} catch (ParseException e) {
					System.out.println(e.getMessage());
				}
				cal.setTime(date);
				cal.add(12, -5);
				Date lasttime = cal.getTime();
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				String str = sdf.format(lasttime);
				parms.add(new GlobalParameter("time", str));
			}
			List<RowBase> rows1 = DataUtil.getSelectRows(sql1, parms);
			if (rows1 != null && rows1.size() > 0) {
				String result = JSONUtils.toJSONString(rows1);
				return JSONUtils.toJSONString(rows1);
			} else {
				return "[]";
			}
		}
	}
	/**
	 * 获取当天现场考核历史数据
	 */
	public String getXckhData(String stationId, String userId) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		if (stationId.isEmpty() || userId.isEmpty()) {
			return "[]";
		}
		String sql1 = "select t1.c_userealname as jcname,t2.c_userealname as hcname,t3.c_userealname as gsname,t.* from  SUPPLY_WATER_STATION_CHECK t "
				+ " left join safe_user t1 on t1.s_userid = t.inspector_userid "
				+ " left join safe_user t2 on t2.s_userid = t.Inspect_Id "
				+ " left join safe_user t3 on t3.s_userid = t.COMPANY_USERID  where t.station_code = '" + stationId
				+ "' " + " and t.inspector_userid ='" + userId
				+ "'and  to_char(t.check_date,'yyyy-mm-dd') = to_char(sysdate,'yyyy-mm-dd')";
		List<RowBase> rows1 = DataUtil.getSelectRows(sql1, parms);
		JSONArray jsonObj = new JSONArray();
		for (int i = 0; i < rows1.size(); i++) {
			JSONObject chidlobject = new JSONObject();
			String childGuid = rows1.get(i).getSafeString("GUID");
			String sql = "select t1.S_DOMAINCAPTION as equipmentName,t.* from SUPPLY_WATER_STATION_CHECKITEM t "
					+ "left join (select t.S_DOMAINCODE,t.S_DOMAINCAPTION  from data_defulatdomain  t "
					+ "where S_DOMAINNAME='检测设备代号' )t1 on t1.s_domaincode = t.poll_code where check_id = '" + childGuid
					+ "'";
			List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
			chidlobject.put("parent", rows1.get(i));
			chidlobject.put("child", rows);
			jsonObj.add(chidlobject);
		}
		// String sql = "select t.*,t2.* from SUPPLY_WATER_STATION_CHECK t left
		// join "
		// + "SUPPLY_WATER_STATION_CHECKITEM t2 on t.guid=t2.check_id where
		// t.station_code = '" + stationId + "' "
		// + "and t.inspector_userid ='"+ userId +"'and
		// to_char(t.check_date,'yyyy-mm-dd') = to_char(sysdate,'yyyy-mm-dd')";
		// List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (jsonObj != null && jsonObj.size() > 0) {
			return JSONUtils.toJSONString(jsonObj.toString());
		} else {
			return "[]";
		}
	}
	/**
	 * android移动运营供水核查人员名称
	 * 
	 * @param userName
	 * @param password
	 * @return
	 * @throws Exception
	 */
	public String getGsXCKHHCName(String groupId) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t.c_userealname,t.s_userid from (select u.s_userid,u.c_username,u.c_userealname,"
				+ "r.c_rolename from safe_user u left join safe_userrole ur on u.s_userid = "
				+ "ur.s_userid left join safe_role r on r.i_roleid = ur.s_roleid ) t where t.c_rolename = '核查人员'";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() > 0) {
			String result = JSONUtils.toJSONString(rows);
			return JSONUtils.toJSONString(rows);
		} else {
			return "[]";
		}
	}
	/**
	 * 获取供水公司人员名称
	 */
	public String getGsXckhGsName() {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select t.c_userealname,t.s_userid from (select u.s_userid,u.c_username,u.c_userealname,"
				+ "r.c_rolename from safe_user u left join safe_userrole ur on u.s_userid = "
				+ "ur.s_userid left join safe_role r on r.i_roleid = ur.s_roleid ) t where t.c_rolename = '公司运营人员'";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() > 0) {
			String result = JSONUtils.toJSONString(rows);
			return JSONUtils.toJSONString(rows);
		} else {
			return "[]";
		}
	}
	/**
	 * android获取供水现场考核参数
	 * 
	 * @param userName
	 * @param password
	 * @return
	 * @throws Exception
	 */
	public String getGsXckhParam(String stationCode) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "SELECT t1.s_domaincaption,t1.s_domaincode from BC_SITE_POLL t "
				+ "left join (select t.S_DOMAINCODE,t.S_DOMAINCAPTION  from data_defulatdomain  t "
				+ "where S_DOMAINNAME='检测设备代号') t1 on t.name = t1.S_DOMAINCODE  where 1= 1 ";
		if (!stationCode.isEmpty()) {
			sql += " and t.SITE_ID=@stationCode";
			parms.add(new GlobalParameter("stationCode", stationCode));
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}
	/**
	 * android供水现场考核数据保存
	 */
	public String saveGsXckhData(String saveData, String listMap) {
		List<GlobalParameter> parms = new ArrayList();
		String savesql = "insert into SUPPLY_WATER_STATION_CHECK(GUID,STATION_CODE,IS_DATA_TRAN_WORK,IS_HOUSE_CLEAN,IS_OPERATION_WORK"
				+ ",OPERATION_FREQUENCY,COMPARED_FREQUENCY,CHECK_POINT,NOTE,CHECK_DATE,INSPECTOR_USERID,COMPANY_USERID,CHECK_STATUS,INSPECT_ID)values"
				+ "(@GUID,@STATION_CODE,@IS_DATA_TRAN_WORK,@IS_HOUSE_CLEAN,@IS_OPERATION_WORK,@OPERATION_FREQUENCY,"
				+ "@COMPARED_FREQUENCY,@CHECK_POINT,@NOTE,@CHECK_DATE,@INSPECTOR_USERID,@COMPANY_USERID,@CHECK_STATUS,@INSPECT_ID)";
		RowBase entity = JSONConvertUtils.convertToEntity(saveData);
		JSONObject data = JSONUtils.toJSONObject(saveData);
		JSONArray list = JSONUtils.toJSONArray(listMap);
		parms.clear();
		String GUID = UUID.randomUUID().toString();
		parms.add(new GlobalParameter("GUID", GUID));
		parms.add(new GlobalParameter("STATION_CODE", data.get("STATION_CODE").toString()));
		parms.add(new GlobalParameter("IS_DATA_TRAN_WORK", data.get("IS_DATA_TRAN_WORK").toString()));
		parms.add(new GlobalParameter("IS_HOUSE_CLEAN", data.get("IS_HOUSE_CLEAN").toString()));
		parms.add(new GlobalParameter("IS_OPERATION_WORK", data.get("IS_OPERATION_WORK").toString()));
		parms.add(new GlobalParameter("OPERATION_FREQUENCY", data.get("OPERATION_FREQUENCY").toString()));
		parms.add(new GlobalParameter("COMPARED_FREQUENCY", data.get("COMPARED_FREQUENCY").toString()));
		parms.add(new GlobalParameter("CHECK_POINT", data.get("CHECK_POINT").toString()));
		parms.add(new GlobalParameter("NOTE", data.get("NOTE").toString()));
		parms.add(new GlobalParameter("CHECK_STATUS", "3"));
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd ");
		// Date date = null;
		Date date = null;
		try {
			date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(data.get("CHECK_DATE").toString());
		} catch (ParseException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		parms.add(new GlobalParameter("CHECK_DATE", date));
		parms.add(new GlobalParameter("INSPECTOR_USERID", data.get("INSPECTOR_USERID").toString()));
		parms.add(new GlobalParameter("INSPECT_ID", data.get("INSPECT_ID").toString()));
		parms.add(new GlobalParameter("COMPANY_USERID", data.get("COMPANY_USERID").toString()));
		int i = DataUtil.ExecuteUpdateSql(savesql, parms);
		for (int j = 0; j < list.size(); j++) {
			String sql = "insert into SUPPLY_WATER_STATION_CHECKITEM(GUID,CHECK_ID,POLL_CODE,EQUIPMENT_VALUE,STANDARD_VALUE,IS_PASS,RTD) values"
					+ "(@GUID,@CHECK_ID,@POLL_CODE,@EQUIPMENT_VALUE,@STANDARD_VALUE,@IS_PASS,@RTD)";
			List<GlobalParameter> childparms = new ArrayList();
			String GUID1 = UUID.randomUUID().toString();
			childparms.add(new GlobalParameter("GUID", GUID1));
			childparms.add(new GlobalParameter("CHECK_ID", GUID));
			childparms.add(new GlobalParameter("POLL_CODE", list.getJSONObject(j).opt("POLL_CODE").toString()));
			try {
				childparms.add(new GlobalParameter("EQUIPMENT_VALUE",
						Float.parseFloat(list.getJSONObject(j).opt("EQUIPMENT_VALUE").toString())));
			} catch (Exception e) {
				childparms.add(new GlobalParameter("EQUIPMENT_VALUE", null));
			}
			try {
				childparms.add(new GlobalParameter("STANDARD_VALUE",
						Float.parseFloat(list.getJSONObject(j).opt("STANDARD_VALUE").toString())));
			} catch (Exception e) {
				childparms.add(new GlobalParameter("STANDARD_VALUE", null));
			}
			//
			// childparms.add(new GlobalParameter("EQUIPMENT_VALUE",
			// null ==
			// list.getJSONObject(j).opt("EQUIPMENT_VALUE")?"":Float.parseFloat(list.getJSONObject(j).opt("EQUIPMENT_VALUE").toString())));
			// childparms.add(new GlobalParameter("STANDARD_VALUE",
			// null
			// ==list.getJSONObject(j).opt("STANDARD_VALUE")?"":Float.parseFloat(list.getJSONObject(j).opt("STANDARD_VALUE").toString())));
			childparms.add(new GlobalParameter("IS_PASS", list.getJSONObject(j).opt("IS_PASS").toString()));
			childparms.add(new GlobalParameter("RTD", list.getJSONObject(j).opt("RTD").toString()));
			i = i + DataUtil.ExecuteUpdateSql(sql, childparms);
		}
		if (i == 0) {
			return "{\"result\":true}";
		} else {
			return "{\"result\":false}";
		}
	}
	/**
	 * 获取未处理、已处理供水数据
	 * 
	 * @param jobId
	 * @param station_id
	 * @return
	 */
	public String getWaterSupplyJobData(String jobId, String station_id) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		// 所有任务语句
		String ProcessedSql = "select t7.task_code,t7.task_status,t2.name as station_name,t7.job_id,to_char(t7.start_time, 'yyyy-mm-dd') as start_time,\n"
				+ "       to_char(t7.end_time, 'yyyy-mm-dd hh24:mi:ss') as end_time,t8.TASK_TOLERANCE,to_char(t7.FINISH_TIME, 'yyyy-mm-dd') as FINISH_TIME,t2.exp_no\n"
				+ "  from BC_SITE_INFO t2\n"
				+ "  left join OPERATION_GROUP_STATION_ASSO t3 on t2.exp_no = t3.station_id\n"
				+ "  left join OPERATION_TASK t7 on t3.station_id = t7.station_id\n"
				+ "  left join OC_TASK_CONFIG t8 on t7.station_id = t8.station_id\n" + "  where 1 = 1 ";
		if (jobId != null && !jobId.equals("")) {
			ProcessedSql += " and t7.JOB_ID =@jobId";
			ProcessedSql += " and t8.JOB_ID =@jobId";
			parms.add(new GlobalParameter("jobId", jobId));
		}
		if (station_id != null && !station_id.equals("")) {
			ProcessedSql += " and t7.station_id =@station_id";
			ProcessedSql += " and t8.station_id =@station_id";
			parms.add(new GlobalParameter("station_id", station_id));
		}
		ProcessedSql += " order by end_time desc";
		List<RowBase> rowProcessed = DataUtil.getSelectRows(ProcessedSql, parms);
		JSONArray ProcessedData = new JSONArray();
		JSONArray PendingData = new JSONArray();
		JSONArray TimeoutHandlingData = new JSONArray();
		if (rowProcessed != null && rowProcessed.size() > 0) {
			for (int i = 0; i < rowProcessed.size(); i++) {
				HashMap<String, Object> d = rowProcessed.get(i);
				String task_status = d.get("TASK_STATUS").toString();
				Calendar deathCal = Calendar.getInstance();
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				String et = d.get("END_TIME").toString();// 截止时间
				Date et_date = new Date();
				Date fishtime_date = new Date();
				Date nowdate = new Date();
				try {
					et_date = sdf.parse(et);
					deathCal.setTime(et_date);
				} catch (ParseException e) {

					e.printStackTrace();
				}
				int timeCycleNum = Integer.parseInt(d.get("TASK_TOLERANCE").toString().replaceAll("[a-zA-Z]", ""));
				if (d.get("TASK_TOLERANCE").toString().indexOf("D") > 0) {
					deathCal.add(Calendar.DAY_OF_MONTH, timeCycleNum);
				} else if (d.get("TASK_TOLERANCE").toString().indexOf("M") > 0) {
					deathCal.add(Calendar.MONTH, timeCycleNum);
				}
				Date truefishtime = deathCal.getTime();

				if (task_status.equals("0")) {// 未处理
					PendingData.add(d);
					/*
					 * if (truefishtime.getTime() >= nowdate.getTime()) {
					 * PendingData.add(d); } else { TimeoutHandlingData.add(d);
					 * }
					 */
				}
				if (task_status.equals("1")) {// 已处理
					try {
						if (null != d.get("FINISH_TIME")) {
							String fishtime = d.get("FINISH_TIME").toString();// 完成时间
							fishtime_date = sdf.parse(fishtime);
							ProcessedData.add(d);
						}

					} catch (ParseException e) {

						e.printStackTrace();
					}

				}
			}
		}

		JSONObject jsobj = new JSONObject();
		jsobj.put("PendingData", PendingData);
		jsobj.put("ProcessedData", ProcessedData);
		jsobj.put("TimeoutHandlingData", TimeoutHandlingData);
		List<JSONObject> allData = new ArrayList<>();
		allData.add(jsobj);
		String result = JSONUtils.toJSONString(allData);
		return JSONUtils.toJSONString(result);
	}
	/**
	 * 实时更新定期维护每一项工作值
	 * 
	 * @param TASK_CODE
	 * @param filedName
	 * @param value
	 * @return
	 */
	@RequestMapping("/updateMaintainanceOne")
	@ResponseBody
	public String updateMaintainanceOne(String tableName, String row, String TASK_CODE) throws Exception {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sqldata = "select * from OP_MAIN_RECORD where 1=1 and TASK_CODE='" + TASK_CODE + "'";
		List<RowBase> rows = DataUtil.getSelectRows(sqldata, parms);
		JSONObject json = JSONObject.fromObject(row);
		if (rows.size() > 0) {
			json.put("FIELD_ISNEW", "flase");

		}

		tableName = tableName.toUpperCase();
		try {
			RowBase entity = JSONConvertUtils.convertToEntity(json.toString());
			Object obj = entity.getValue("_IS_DOMAIN_TRUE");
			if (obj != null && obj.toString().toLowerCase().equals("true")) {
				return null;
			} else {
				return tableSave(tableName, entity);
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
	}
	private String tableSave(String tableName, RowBase entity) throws Exception {
		ITableFactory tableFactory = (ITableFactory) SpringBeanFactory.getBean("TableFactory");
		ITable pTable = tableFactory.openTable(tableName);

		String returnString = FormEditInterceptorClass.BeforeDbEditOptionEx(pTable, entity, DbEditType.Insert);
		if (StringUtils.IsNullOrSpace(returnString)) {
			pTable.startEditing();
			try {
				pTable.save(entity);

				// 再做一次字典转议
				ConvertCaptionUtils.convertCaptionField(pTable, entity);
				ObjectMapper mapper = new ObjectMapper();
				String userMapJson = mapper.writeValueAsString(entity);
				pTable.stopEditing(true);

				return userMapJson;
			} catch (Exception e) {
				pTable.stopEditing(false);
				throw e;
			}
		} else {
			return returnString;
		}
	}
	/**
	 * 获取日常巡检所有值
	 * 
	 * @param task_code
	 * @param job_id
	 * @return
	 */
	@RequestMapping("/getTaskDataByTaskID")
	@ResponseBody
	public String getTaskDataByTaskID(String task_code, String job_id) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "";
		if (job_id != null && !job_id.equals("")) {
			if (job_id.equals("fa3ecf1a-4820-4f9f-b7b7-2553584ee7ba")) {// 日常巡检
				sql = "select A01,A02,A03,A04,A05,A06,B01,B02,B03,B04,B05,B06,C01,C02,C03,C04,C05,C06,C07,C08,C09,C10,C21,C22,C23,C24,C25,C31,C32,C33,C34,C35,D01,D02,D03,D04,D05,D06,D11,D12,D13,D14,D15,D16 from OP_INSP_RECORD where 1=1 ";
			}
			if (job_id.equals("0bddcd82-73ff-4ee7-85af-491108b7f374")) {// 定期维护
				sql = "select A01,A02,A03,A04,A05,A06,B01,B02,B03,B04,B05,B06,C01,C02,C03,C04,C05,C06,C07,C08,C09,C10,"
						+ "C21,C22,C23,C24,C25,C26,C31,C32,C33,C34,C35,C36,C37,C38,C41,C42,C43,C44,C45,C46,C47 from OP_MAIN_RECORD where 1=1 ";
			}
			if (job_id.equals("16fe2eed-eba1-4b1c-8ece-46a725a5797b")) {// 供水定期维护
				sql = "select A01,A02,A03,A04,A05,A06,B01,B02,B03,B04,B05,B06,C01,C02,C03,C04,C05,C06,C07,C08,C09,C10,"
						+ "C21,C22,C23,C24,C25,C26,C31,C32,C33,C34,C35,C36,C37,C38,C41,C42,C43,C44,C45,C46,C47 from OP_MAIN_RECORD where 1=1 ";
			}
			if (task_code != null && !task_code.equals("")) {
				sql += " and TASK_CODE =@task_code";
				parms.add(new GlobalParameter("task_code", task_code));
			}
		} else {
			return "{\"result\":false}";
		}
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() > 0) {
			RowBase row = rows.get(0);
			JSONObject json = JSONObject.fromObject(row);
			String jsonRrsult = json.toString();
			return jsonRrsult;
		} else {
			return "{\"result\":false}";
		}
	}
	/**
	 * android移动运营获取站点所属水司
	 * 
	 * @param userName
	 * @param password
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getWaterCompanyList")
	@ResponseBody
	public String getWaterCompanyList(String groupId) {
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "select count(t1.exp_no)as num,t.name,t1.wwtp_id as s_id from BC_ENTERPRISE_ATTR t left join BC_SITE_INFO t1 "
				+ "on t.exp_no = t1.wwtp_id left join OPERATION_GROUP_STATION_ASSO t2 on t1.exp_no = "
				+ "t2.station_id where t1.STATION_CATEGORY = '3' and t.POLL_TYPE='3'";
		if (!groupId.isEmpty()) {
			sql += " and t2.OPERATION_GROUP_ID =@GUID ";
			parms.add(new GlobalParameter("GUID", groupId));
		}
		sql += " group by t.name,t1.wwtp_id";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);

		if (rows != null && rows.size() > 0) {
			String result = JSONUtils.toJSONString(rows);
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}
	/**
	 * 更新供水数据比对详情数据
	 * 
	 * @param flow_type
	 * @param wwtp_id
	 * @return
	 */
	@RequestMapping("/updateGSSJBDDetailData")
	@ResponseBody
	public String updateGSSJBDDetailData(String GUID, String online, String def) {
		if (GUID.isEmpty() || online.isEmpty() || def.isEmpty()) {
			return "{\"result\":false}";
		}
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "update  DATA_COMPARISON set MEASURED_VALUE = @MEASURED_VALUE,GBMETHOD_VALUE = @GBMETHOD_VALUE where GUID =@GUID";
		parms.add(new GlobalParameter("GUID", GUID));
		parms.add(new GlobalParameter("MEASURED_VALUE", online));
		parms.add(new GlobalParameter("GBMETHOD_VALUE", def));

		int i = DataUtil.ExecuteUpdateSql(sql, parms);
		if (i == 0) {
			return "{\"result\":true}";
		} else {
			return "{\"result\":false}";
		}
	}
	/**
	 * 更新供水备件耗材更换详情数据
	 * 
	 * @param flow_type
	 * @param wwtp_id
	 * @return
	 */
	@RequestMapping("/updateGSBJHCGHDetailData")
	@ResponseBody
	public String updateGSBJHCGHDetailData(String GUID, String upnum, String upunit, String status) {
		if (GUID.isEmpty() || upnum.isEmpty() || upunit.isEmpty()) {
			return "{\"result\":false}";
		}
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "update  OP_MATE_REPLACE set material_quantity = @material_quantity,material_unit = @material_unit,replace_result = @replace_result where GUID =@GUID";
		parms.add(new GlobalParameter("GUID", GUID));
		parms.add(new GlobalParameter("material_quantity", upnum));
		parms.add(new GlobalParameter("material_unit", upunit));
		parms.add(new GlobalParameter("replace_result", status));

		int i = DataUtil.ExecuteUpdateSql(sql, parms);
		if (i == 0) {
			return "{\"result\":true}";
		} else {
			return "{\"result\":false}";
		}
	}
	/**
	 * 更新供水异常处理详情数据
	 * 
	 * @param flow_type
	 * @param wwtp_id
	 * @return
	 */
	@RequestMapping("/updateGSYCCLDetailData")
	@ResponseBody
	public String updateGSYCCLDetailData(String GUID, String EXCEPTION_REASON, String process) {
		if (GUID.isEmpty() || EXCEPTION_REASON.isEmpty() || process.isEmpty()) {
			return "{\"result\":false}";
		}
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		String sql = "update  OP_ALAR_PROC set EXCEPTION_REASON = @EXCEPTION_REASON,EXCEPTION_PROCESS = @EXCEPTION_PROCESS where GUID =@GUID";
		parms.add(new GlobalParameter("GUID", GUID));
		parms.add(new GlobalParameter("EXCEPTION_REASON", EXCEPTION_REASON));
		parms.add(new GlobalParameter("EXCEPTION_PROCESS", process));

		int i = DataUtil.ExecuteUpdateSql(sql, parms);
		if (i == 0) {
			return "{\"result\":true}";
		} else {
			return "{\"result\":false}";
		}
	}
	/**
	 * 供水 访问频率：高 获取报警状态，返回是报警次数
	 */
	public String getSupplyWarnState(String groupId) {
		JSONObject resultJson = new JSONObject();
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		parms.add(new GlobalParameter("groupId", groupId));
		// 获取报警状态 1 表示有报警
		String sql = "select t.TYPE from OP_ALAR_INFO t,"
				+ "(select t1.OPERATION_GROUP_ID,t1.STATION_ID,t2.CODE "
				+ "from OPERATION_GROUP_STATION_ASSO t1,MONITOR_STATION t2 WHERE t2.STATION_CATEGORY = '3' and t1.STATION_ID = t2.CODE ";

		// 如果组ID为空，则查询所有的报警信息
		if (groupId != null && !groupId.isEmpty()) {
			sql += " and t1.operation_group_id= @groupId ";
		}
		sql += ")t2 where t.station_code = t2.station_id AND t.is_recover ='0'and t.continue_time>30";

		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			resultJson.put("warnCount", String.valueOf(rows.size()));
		} else {
			resultJson.put("warnCount", "0");
		}
		// 返还结果
		return resultJson.toString();
	}
	/**
	 * 根据站点获取供水未完成任务数列表
	 * @return
	 */
	public String getSupplyTaskNum(String stationId){
		List<GlobalParameter> parms = new ArrayList();
		String sql = "select count(t.job_id) as totalnum,t.job_id from OP_TASK t  where t.station_id = @stationId and t.task_status = '0' group by t.job_id ";
		parms.add(new GlobalParameter("stationId", stationId));
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null && rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return null;
		}
	}
	public String deleteSupplyTask(String taskCode){
		List<GlobalParameter> parms = new ArrayList();
		String sql = "delete from OP_TASK where TASK_STATUS = '0' AND TASK_CODE = @taskCode";
		parms.add(new GlobalParameter("taskCode", taskCode));
		int deleteResult = DataUtil.ExecuteUpdateSql(sql, parms);
		if (deleteResult == 0) {
			return "0";
		} else {
			return "1";
		}
	}
}
